home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
026-050
/
049
/
plot
/
plotter.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-13
|
12KB
|
523 lines
/* plotter.c */
double a1,a2,b1,b2,b3,x,y,zcord;
char trig,stash;
char z[30],temp[30];
short converted[15],h,h1,v,v1;
extern SHORT mx,my;
double store1,store2,store3,temp1;
int length,spin,tip,again;
extern double magx,magy;
extern int SPCos(),SPSin(),SPTieee(),SPFieee(),SPAtan(),SPTan();
plotter()
{
double rd,xsp,ysp,ymax,xmax,ymin,xmin;
ymax=3.0;
ymin=-3.0;
xmax=3.0;
xmin=-3.0;
xsp=(xmax-xmin)/14.0;
ysp=(ymax-ymin)/14.0;
xmax+=.05;
ymax+=.05;
strcpy(temp,z);
SetAPen(rp,31);
SetDrMd(w->RPort,JAM1);
RectFill(w->RPort,0,0,319,199);
SetAPen(rp,4);
rd=3.14159/180.0;
a1=cos(spin*rd);
a2=sin(spin*rd);
b1=-sin(tip*rd)*sin(spin*rd);
b2=sin(tip*rd)*cos(spin*rd);
b3=cos(tip*rd);
for (x=xmin;x<=xmax;x+=xsp){
y=ymin;
if(x==xmin)
translate();
process();
scale();
h1=h;
v1=v;
for (y=ymin;y<=ymax;y+=ysp){
process();
scale();
if (v1<0)
v1=-10;
if (v1>200)
v1=210;
if (h1<0)
h1=-10;
if (h1>319)
h1=330;
if (v<0)
v=-10;
if (v>200)
v=210;
if (h<0)
h=-10;
if (h>319)
h=330;
Move(rp,h1,v1);
Draw(rp,h,v);
h1=h;
v1=v;
}
}
for (y=ymin;y<=ymax;y+=ysp){
x=xmin;
process();
scale();
h1=h;
v1=v;
for (x=xmin;x<=xmax;x+=xsp){
process();
scale();
if (v1<0)
v1=-10;
if (v1>200)
v1=210;
if (h1<0)
h1=-10;
if (h1>319)
h1=330;
if (v<0)
v=-10;
if (v>200)
v=210;
if (h<0)
h=-10;
if (h>319)
h=330;
Move(rp,h1,v1);
Draw(rp,h,v);
h1=h;
v1=v;
}
}
}
scale()
{
double q,p;
q=a1*x+a2*y;
q=q*magx+(double)mx;
h=(short)q;
p=b1*x+b2*y+b3*zcord;
p=(double)my-p*magy;
v=(short)p;
}
translate()
{
char reduce[30],symbol;
register int a,n;
length=strlen(temp)-1;
for (n=0;n<=length;n++){
symbol=temp[n];
converted[n]=0;
switch(symbol) {
case 'x':
case 'X':
converted[n]=-1;
break;
case 'y':
case 'Y':
converted[n]=-2;
break;
case '*':
converted[n]=-3;
break;
case '-':
converted[n]=-4;
break;
case '/':
converted[n]=-5;
break;
case '+':
converted[n]=-6;
break;
case 's':
case 'S':
converted[n]=-7;
if(toupper(temp[n+1])=='I')
temp[n+1]='0';
if(toupper(temp[n+2])=='N')
temp[n+2]='0';
break;
case 'c':
case 'C':
converted[n]=-8;
if(toupper(temp[n+1])=='O')
temp[n+1]='0';
if(toupper(temp[n+2])=='S')
temp[n+2]='0';
break;
case 't':
case 'T':
converted[n]=-9;
if(toupper(temp[n+1])=='A')
temp[n+1]='0';
if(toupper(temp[n+2])=='N')
temp[n+2]='0';
break;
case 'a':
case 'A':
converted[n]=-10;
if(toupper(temp[n+1])=='T')
temp[n+1]='0';
if(toupper(temp[n+2])=='N')
temp[n+2]='0';
break;
case '(':
case ' ':
case ')':
case '0':
converted[n]=0;
break;
default:
converted[n]=symbol-48;
}
}
a=0;
for (n=0;n<=length;n++){
if (converted[n]!=0){
reduce[a]=converted[n];
a++;
}
}
a--;
for (n=0;n<=a;n++)
converted[n]=reduce[n];
length=a;
}
process()
{
register int convert,n,num;
zcord=0;
num=0;
store1=0;
store2=0;
store3=0;
stash='0';
trig='0';
again=0;
for (n=0;n<=length;n++){
convert=converted[n];
if (convert>0){
num++;
if (num==1){
store1=convert;
if (n==length)
tally();
else
if (num>10 && converted[n+1] <-2)
tally();
}
if (num>1 && num<11){
store1=store1*convert;
if (n==length)
tally();
else
if (num>10 && converted[n+1] <-2)
tally();
}
if (num==11){
store2=convert;
if (n==length)
tally();
else{
if (num>10 && converted[n+1]<-2 && converted[n+1]>-7)
tally();
}
}
if (num>11){
store2=store2*convert;
if (n==length)
tally();
else{
if (num>10 && converted[n+1]<-2 && converted[n+1]>-7)
tally();
}
}
}
else {
switch(convert){
case -1:
num++;
if (num==1){
store1=x;
if (n==length){
tally();
break;
}
if (num>10 && converted[n+1] <-2)
tally();
break;
}
if (num>1 && num<11){
store1=store1*x;
if (n==length){
tally();
break;
}
if (num>10 && converted[n+1] <-2)
tally();
break;
}
if (num==11){
store2=x;
if (n==length){
tally();
break;
}
if (num>10 && converted[n+1] <-2)
tally();
break;
}
if (num>11){
store2=store2*x;
if (n==length){
tally();
break;
}
if (num>10 && converted[n+1] <-2)
tally();
}
break;
case -2:
num++;
if (num==1){
store1=y;
if (n==length){
tally();
break;
}
if (num>10 && converted[n+1] <-2)
tally();
break;
}
if (num>1 && num<11){
store1=store1*y;
if (n==length){
tally();
break;
}
if (num>10 && converted[n+1] <-2)
tally();
break;
}
if (num==11){
store2=y;
if (n==length){
tally();
break;
}
if (num>10 && converted[n+1] <-2)
tally();
break;
}
if (num>11){
store2=store2*y;
if (n==length){
tally();
break;
}
if (num>10 && converted[n+1] <-2)
tally();
}
break;
case -3:
stash='*';
num=10;
again++;
break;
case -4:
stash='-';
num=10;
again++;
break;
case -5:
stash='/';
num=10;
again++;
break;
case -6:
stash='+';
num=10;
again++;
break;
case -7:
trig='S';
num=10;
again++;
store3=store1;
if (again==1){
temp1=store1;
if (temp1==0)
temp1=1.0;
break;
}
else{
temp1=store2;
if (temp1==0)
temp1=1.0;
}
break;
case -8:
trig='C';
num=10;
again++;
store3=store1;
if (again==1){
temp1=store1;
if (temp1==0)
temp1=1.0;
break;
}
else{
temp1=store2;
if (temp1==0)
temp1=1.0;
}
break;
case -9:
trig='T';
num=10;
again++;
store3=store1;
if (again==1){
temp1=store1;
if (temp1==0)
temp1=1.0;
break;
}
else{
temp1=store2;
if (temp1==0)
temp1=1.0;
}
break;
case -10:
trig='A';
num=10;
again++;
store3=store1;
if (again==1){
temp1=store1;
if (temp1==0)
temp1=1.0;
break;
}
else{
temp1=store2;
if (temp1==0)
temp1=1.0;
}
break;
}
}
}
}
tally()
{
if (trig!='0'){
switch(trig){
case 'S':
k1.num1=store2;
k1.i1=SPFieee(k1.i1);
k2.i2=SPSin(k1.i1); /* sin(store2) */
k2.i2=SPTieee(k2.i2);
store1=temp1*k2.num2;
zcord=store1;
store2=0;
trig='0';
break;
case 'C':
k1.num1=store2;
k1.i1=SPFieee(k1.i1);
k2.i2=SPCos(k1.i1); /* cos(store2) */
k2.i2=SPTieee(k2.i2);
store1=temp1*k2.num2;
zcord=store1;
store2=0;
trig='0';
break;
case 'T':
k1.num1=store2;
k1.i1=SPFieee(k1.i1);
k2.i2=SPTan(k1.i1); /* tan(store2) */
k2.i2=SPTieee(k2.i2);
store1=temp1*k2.num2;
zcord=store1;
store2=0;
trig='0';
break;
case 'A':
k1.num1=store2;
k1.i1=SPFieee(k1.i1);
k2.i2=SPAtan(k1.i1); /* atan(store2) */
k2.i2=SPTieee(k2.i2);
store1=temp1*k2.num2;
zcord=store1;
store2=0;
trig='0';
break;
}
switch (stash){
case '*':
store1=store3*store1;
zcord=store1;
break;
case '-':
store1=store3-store1;
zcord=store1;
break;
case '/':
store1=store3/store1;
zcord=store1;
break;
case '+':
store1=store3+store1;
zcord=store1;
break;
}
}
else{
switch(stash){
case '*':
store1=store1*store2;
zcord=store1;
again++;
store2=0;
break;
case '-':
store1=store1-store2;
zcord=store1;
again++;
store2=0;
break;
case '/':
store1=store1/store2;
zcord=store1;
again++;
store2=0;
break;
case '+':
store1=store1+store2;
zcord=store1;
again++;
store2=0;
break;
default:
zcord=store1;
}
}
}